import { createStore } from "vuex";
import { testData,testPosts,ColumnProps,PostProps } from "./testData"; './testData'
interface UserProps{
  isLogin: boolean;
  name?: string;
  id?:number;
}
export interface GlobalDataProps{
  columns: ColumnProps[],
  posts:PostProps[],
  user:UserProps;
}
const store= createStore<GlobalDataProps>({
  state:{
    columns:testData,
    posts:testPosts,
    user:{isLogin:false}
  },
  mutations:{
    login(state){
      state.user = {...state.user,isLogin:true, name:"miumiu"}
    }
  },
  getters:{
    biggerColumnLen(state){
      return state.columns.filter(c=>c.id>2).length
    },
    getColumnById:(state)=>(id:number)=>{
      return state.columns.find(c=>c.id===id)
    },
    getPostsById:(state)=>(cid:number)=>{
      return state.posts.filter(post => post.columnId === cid)
    }
  }
})

export default store